package com.springapp.mvc.controller;

import com.springapp.mvc.cache.annotation.SmartCache;
import com.springapp.mvc.dao.student.StudentDao;
import com.springapp.mvc.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/")
public class HelloController {

	@Autowired
	private StudentDao studentDao;

	@RequestMapping(method = RequestMethod.GET)
	public String printWelcome(ModelMap model) {
		model.addAttribute("message", "Hello world!");
		return "hello";
	}

	@RequestMapping(value="find",method = RequestMethod.GET)
	public ModelAndView findSutudent(int id,ModelAndView modelAndView){
	    Student student= studentDao.find(id);
		System.out.println(student);
		modelAndView.setViewName("find");
		modelAndView.addObject("student",student);
		return modelAndView;
	}
}